package controller;

import Pojo.Houselist;
import dao.SearchHouselistMapper;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

import java.util.List;

/**

 **/
@Controller
public class searchController {
    @Autowired
    private SearchHouselistMapper searchHouselistMapper;

    @RequestMapping("/search")
    public String search(String searchbox, HttpServletRequest request, Model model){
        String selectOP1 = request.getParameter("selectOP");
        //i获取到1为根据地址搜索
        //i获取到2为根据面积搜索
        //i获取到3为根据价格搜索
        int i = Integer.parseInt(selectOP1);
        switch (i){
            case 1:
                List<Houselist> houselists = searchHouselistMapper.selectByaddress(searchbox);
                model.addAttribute("mainPage","searchaddress.jsp");
                model.addAttribute("addressSearch",houselists);
                break;
            case 2:
                List<Houselist> houselists1 = searchHouselistMapper.selectByarea(searchbox);
                model.addAttribute("mainPage","searchaddress.jsp");
                model.addAttribute("addressSearch",houselists1);
                break;
            case 3:
                List<Houselist> houselists2 = searchHouselistMapper.selectByprice(searchbox);
                model.addAttribute("mainPage","searchaddress.jsp");
                model.addAttribute("addressSearch",houselists2);
                System.out.println(houselists2);
                break;
        }

        return "zuke/main";
    }

    @RequestMapping("/searchadmin")
    public String searchadmin(String searchbox, HttpServletRequest request, Model model){

        String selectOP1 = request.getParameter("selectOP");
        //i获取到1为根据地址搜索
        //i获取到2为根据面积搜索
        //i获取到3为根据价格搜索
        int i = Integer.parseInt(selectOP1);
        switch (i){
            case 1:
                List<Houselist> houselists = searchHouselistMapper.selectByaddress(searchbox);
                model.addAttribute("mainPage","searchaddress.jsp");
                model.addAttribute("addressSearch",houselists);
                break;
            case 2:
                List<Houselist> houselists1 = searchHouselistMapper.selectByarea(searchbox);
                model.addAttribute("mainPage","searchaddress.jsp");
                model.addAttribute("addressSearch",houselists1);
                break;
            case 3:
                List<Houselist> houselists2 = searchHouselistMapper.selectByprice(searchbox);
                model.addAttribute("mainPage","searchaddress.jsp");
                model.addAttribute("addressSearch",houselists2);
                System.out.println(houselists2);
                break;
        }
        return "admin/main1";
    }
}
